# -*- coding: utf-8 -*-
# @author: wch
# @file: mousecontrol.py
# @time: 2023/2/3 13:45

# 鼠标回调函数 setMouseCallback（winname,callback,userdata)
# winname 窗口名字
# callback 回调函数
# userdata 给回调函数（callback)设置参数

# callback（event，x,y,flags,userdata)  event 鼠标事件，鼠标的位置（x，y） flags 组合键 （ctrl，shift） userdata
import cv2
import numpy as np


def mouse_callback(event, x, y, flag, userdata):
    print(event, x, y, flag, userdata)


# mouse_callback(1, 100, 100, 16, "666")

# 创建窗口
cv2.namedWindow("mouse", cv2.WINDOW_NORMAL)
cv2.resizeWindow("mouse", 640, 360)

# 设置鼠标回调
cv2.setMouseCallback("mouse", mouse_callback, "123")

img = np.zeros((360, 640, 3), dtype=np.uint8)

while True:
    cv2.imshow("mouse", img)
    key = cv2.waitKey(1)
    if key & 0xFF == ord("q"):
        break
cv2.destroyAllWindows()